<template>
  <div class="container">
    <div style="margin-top: 20px">
      <el-form ref="form"  label-width="80px">
      <el-form-item label="通知主题">
        <el-input v-model="listAdd.theme"></el-input>
      </el-form-item>
      </el-form>
    </div>
    <div v-loading="loading" class="editor"><!--上传图片时得加载画面-->
      <div><quill-editor v-model="listAdd.msg" style="height: 300px;" :options="editorOption"></quill-editor></div>
    </div>
    <div class="fb_button" >
      <el-button type="primary" @click="handleEidt()">修改通知</el-button>
    </div>
  </div>
</template>

<script>

  import {editDetail, getNoticeDetail, sendNotice} from "../../api/notice";
  import  {quillEditor} from 'vue-quill-editor'  // 引入编辑器
  import Quill from 'quill';
  import Parchment from 'parchment';
  // 富文本编辑器外部引用样式  三种样式三选一引入即可
  import 'quill/dist/quill.snow.css'
  // import 'quill/dist/quill.core.css'
  // import 'quill/dist/quill.bubble.css'

  let config = {
    scope: Parchment.Scope.BLOCK,
    whitelist: ['right', 'center', 'justify']
  };
  let AlignStyle = new Parchment.Attributor.Style('align', 'text-align', config);
  export { AlignStyle };
  var Align = Quill.import('attributors/style/align');
  Align.whitelist = ['right', 'center', 'justify'];
  Quill.register(Align, true);

  export default {
    name: 'add',
    props:{
      noticeId:''
    },
    components: {
      quillEditor
    },
    data() {
      return {
        listAdd: {
          msg: '',
          toClass: '1490234176662478850',
          theme:''
        },
        loading: false,
        editorOption: {
          modules: {
            toolbar:[
              ['bold', 'italic', 'underline', 'strike'],    //加粗，斜体，下划线，删除线
              ['blockquote', 'code-block'],     //引用，代码块

              [{ 'header': 1 }, { 'header': 2 }],        // 标题，键值对的形式；1、2表示字体大小
              [{ 'list': 'ordered'}, { 'list': 'bullet' }],     //列表
              [{ 'script': 'sub'}, { 'script': 'super' }],   // 上下标
              [{ 'indent': '-1'}, { 'indent': '+1' }],     // 缩进
              [{ 'direction': 'rtl' }],             // 文本方向

              [{ 'size': ['small', false, 'large', 'huge'] }], // 字体大小
              [{ 'header': [1, 2, 3, 4, 5, 6, false] }],     //几级标题

              [{ 'color': [] }, { 'background': [] }],     // 字体颜色，字体背景颜色
              [{ 'font': [] }],     //字体
              [{ 'align': [] }],    //对齐方式

              ['clean'],    //清除字体样式
            ]
          },
        }
      }
    },
    methods: {
      //获取通知详情
      handleGetDetail(){
        getNoticeDetail({id:this.noticeId}).then(res=>{
          this.listAdd.theme=res.data.theme
          this.listAdd.msg=res.data.msg
          console.log(this.noticeId)
          console.log(res)
        })
      },
      //修改通知
      handleEidt() {
        editDetail({
          id: this.noticeId,
          msg: this.listAdd.msg,
          theme: this.listAdd.theme
        }).then(res => {
          if (res.code == 20000) {
            this.$message.success("修改成功");
            this.listAdd.msg = ''
            this.listAdd.theme=''
          } else {
            this.$message.error(res.msg)
          }
          this.handleGetDetail()
        })
      },

    },
    activated() {
      this.handleGetDetail()
    },
    created() {
    }
  }
</script>

<style scoped>

  .container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .editor {
    width: 80%;
    margin-top: 20px;
  }

  .fb_button {
    display: block;
    margin-top: 100px;
  }

</style>
